package vocoders;

public class GeneralDSP {

	public static double[] conv(double[] data, double[] operator) {
		// Apply the operator to the data, dealing
		// with the index reversal required by
		// convolution.
		int dataLen = data.length;
		int operatorLen = operator.length;
		double[] output=new double[dataLen - operatorLen];
		for (int i = 0; i < dataLen - operatorLen; i++) {
			output[i] = 0;
			for (int j = operatorLen - 1; j >= 0; j--) {
				output[i] += data[i + j] * operator[j];
			}
		}
		return output;
	}

	public static double[] filter(double[] signal, double[] b, double[] a) {
		double[] result = new double[signal.length];
		double[] xBuffer = new double[b.length];
		double[] yBuffer = new double[a.length];

		for (int i = 0; i < signal.length; i++) {
			for (int j1 = 0; j1 < b.length; j1++)
				result[i] += (i - j1 >= 0) ? b[j1] * signal[i - j1] : 0;

			for (int j2 = i; j2 < a.length; j2++)
				result[i] -= a[j2]*yBuffer[j2];
//			 yBuffer[i]=
		}

		return result;
	}

}
